package com.necsv;

import android.content.Context;
import android.util.Log;

import com.google.android.apps.analytics.GoogleAnalyticsTracker;

public class GoogleAnaTool {
	private static final String TAG = "GoogleAnaTool";
	private static GoogleAnalyticsTracker tracker = null;
	public synchronized static void start(Context context)
	{
		if(tracker != null)
			stop(context);
		String sAccount = "UA-32603851-1"; // create account in google Analytics.
		tracker = GoogleAnalyticsTracker.getInstance();
		tracker.startNewSession(sAccount, 0, context);
	}
	
	public synchronized static void stop(Context context)
	{
		if(tracker != null)
		{
			GoogleAnalyticsTracker.getInstance().stopSession();
			tracker = null;
		}
	}
	
	public synchronized static void trackPage(String page){
		if(tracker == null)
		{
			Log.v(TAG, "Err Tracker is nulllll");
		}else
		{
			tracker.trackPageView(page);
			// Track events by specifying a category, action, label and value
			// (all developer-defined fields):

			tracker.trackEvent("Clicks", "Button", "High Road", 0);
			tracker.dispatch();
			Log.v(TAG, "Begin trackger page: " + page);
		}
	}
	
	private synchronized static void track(String page) {
		if (tracker == null) {
			Log.e(TAG, "instance is null");
		} else {
			tracker.trackPageView(page);
			tracker.dispatch();
			Log.v(TAG, page);
		}
	}
	
	public static void trackStarted() {
		track("/");
	}
	
	public synchronized static void trackEvent(String Catelog, String acttion, String label, int value)
	{
		tracker.trackEvent(Catelog, acttion, label, value);
	}
	
	public synchronized static void trackReferrer(String sReferrer)
	{
		if(tracker == null)
		{
			Log.v(TAG, "Err Tracker REferrer is nulllll");
		}else
		{
			tracker.setReferrer(sReferrer);
			Log.v(TAG, "Begin trackger Referrer: " + sReferrer);
		}
	}
	
	

}
